{% extends 'base.html' %}
{% load static %}

{% block title %}私信列表 - Meet活动聚{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-12">
            <div class="card shadow">
                <div class="card-header bg-primary text-white">
                    <h4 class="mb-0"><i class="bi bi-envelope"></i> 私信列表</h4>
                </div>
                <div class="card-body">
                    {% if conversations %}
                    <div class="list-group">
                        {% for conversation in conversations %}
                        <a href="{% url 'social:chat_main' %}" class="list-group-item list-group-item-action">
                            <div class="d-flex justify-content-between align-items-center">
                                <div class="d-flex align-items-center">
                                    {% if conversation.user.avatar %}
                                    <img src="{{ conversation.user.avatar.url }}" class="rounded-circle me-3" width="50" height="50" alt="{{ conversation.user.username }}">
                                    {% else %}
                                    <i class="bi bi-person-circle me-3" style="font-size: 2rem;"></i>
                                    {% endif %}
                                    <div>
                                        <h6 class="mb-1">{{ conversation.user.nickname|default:conversation.user.username }}</h6>
                                        <p class="mb-1 text-muted">
                                            {% if conversation.last_message.sender == user %}
                                                我: {{ conversation.last_message.content|truncatewords:10 }}
                                            {% else %}
                                                {{ conversation.last_message.content|truncatewords:10 }}
                                            {% endif %}
                                        </p>
                                        <small class="text-muted">{{ conversation.last_message.created_at|date:"Y-m-d H:i" }}</small>
                                    </div>
                                </div>
                                {% if conversation.unread_count > 0 %}
                                <span class="badge bg-danger rounded-pill">{{ conversation.unread_count }}</span>
                                {% endif %}
                            </div>
                        </a>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="text-center py-4">
                        <i class="bi bi-envelope-x" style="font-size: 4rem; color: #6c757d;"></i>
                        <h5 class="mt-3">暂无私信</h5>
                        <p class="text-muted">您还没有与任何人开始对话</p>
                        <a href="{% url 'activities:activity_list' %}" class="btn btn-primary">
                            <i class="bi bi-search"></i> 去发现活动
                        </a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}